aspectframe: Fix use in ui files
authorMatthias Clasen <mclasen@redhat.com>
Wed, 5 Aug 2020 18:04:17 +0000 (14:04 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Wed, 5 Aug 2020 18:05:47 +0000 (14:05 -0400)
GtkAspectFrame code assumes that its child will be in
self->child, but that is only the case if we arrange
for <child> in ui files to end up calling
gtk_aspect_frame_set_child(). Therefore, implement
GtkBuildable.

Fixes: #3020
gtk/gtkaspectframe.c

index ba035c4e4237179a961a03a5b143b0b1f7eff2da..b7c2cef769927630e9f6df3d85a2fbd0f104491d 100644 (file)
@@ -51,6 +51,8 @@
 
 #include "gtksizerequest.h"
 
+#include "gtkbuildable.h"
+
 #include "gtkwidgetprivate.h"
 #include "gtkprivate.h"
 #include "gtkintl.h"
@@ -110,11 +112,16 @@ static void gtk_aspect_frame_compute_expand (GtkWidget     *widget,
 static GtkSizeRequestMode
             gtk_aspect_frame_get_request_mode (GtkWidget *widget);
 
+static void gtk_aspect_frame_buildable_init (GtkBuildableIface *iface);
 
 #define MAX_RATIO 10000.0
 #define MIN_RATIO 0.0001
 
-G_DEFINE_TYPE (GtkAspectFrame, gtk_aspect_frame, GTK_TYPE_WIDGET)
+
+G_DEFINE_TYPE_WITH_CODE (GtkAspectFrame, gtk_aspect_frame, GTK_TYPE_WIDGET,
+                         G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
+                                                gtk_aspect_frame_buildable_init))
+
 
 static void
 gtk_aspect_frame_class_init (GtkAspectFrameClass *class)
@@ -253,6 +260,28 @@ gtk_aspect_frame_get_property (GObject         *object,
     }
 }
 
+static GtkBuildableIface *parent_buildable_iface;
+
+static void
+gtk_aspect_frame_buildable_add_child (GtkBuildable *buildable,
+                                      GtkBuilder   *builder,
+                                      GObject      *child,
+                                      const char   *type)
+{
+  if (GTK_IS_WIDGET (child))
+    gtk_aspect_frame_set_child (GTK_ASPECT_FRAME (buildable), GTK_WIDGET (child));
+  else
+    parent_buildable_iface->add_child (buildable, builder, child, type);
+}
+
+static void
+gtk_aspect_frame_buildable_init (GtkBuildableIface *iface)
+{
+  parent_buildable_iface = g_type_interface_peek_parent (iface);
+
+  iface->add_child = gtk_aspect_frame_buildable_add_child;
+}
+
 /**
  * gtk_aspect_frame_new:
  * @xalign: Horizontal alignment of the child within the allocation of